package com.woniu.serverdriveruser.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.internalcommon.dto.ApiBossDriver;
import com.woniu.internalcommon.dto.DriverCarBindingRelationship;
import com.woniu.internalcommon.response.DriverUserExistsResponse;
import com.woniu.internalcommon.response.OrderDriverResponse;
import com.woniu.serverdriveruser.service.DriverCarBindingService;
import com.woniu.serverdriveruser.service.DriverService;
import com.woniu.internalcommon.dto.DriverUser;
import com.woniu.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/driver")
public class DriverController {

    @Autowired
    private DriverService driverService;

    @Autowired
    private DriverCarBindingService driverCarRelationshipService;
    /**
     * 添加/注册司机
     * @param driver
     * @return
     */
    @PostMapping("addDriverUser")
    public ResponseResult addDriverUser(@RequestBody DriverUser driver) {
        driverService.add(driver);
        return  ResponseResult.success("添加成功");
    }

    /**
     * 删除/注销司机
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public ResponseResult deleteById(Long id) {
        driverService.deleteById(id);
        return  ResponseResult.success("删除成功");
    }

    /**
     * 修改司机信息
     * @param driver
     * @return
     */
    @PutMapping("update")
    public ResponseResult updateDriverUser(@RequestBody DriverUser driver) {
        return  driverService.update(driver);
    }

    /**
     * 根据手机号查询司机信息(查司机是否存在)
     * @param driverPhone
     * @return
     */
    @GetMapping("/selectByDriverPhone")
    public ResponseResult<DriverUserExistsResponse>  selectByDriverPhone(@RequestParam("driverPhone") String driverPhone) {
        return driverService.getDriverByPhone(driverPhone);
    }
    /**
     * 根据手机号查询司机信息(查具体信息)
     * @param driverPhone
     * @return
     */
    @GetMapping("/getDriverUserByPhone")
    public ResponseResult<DriverUser> getDriverUserByPhone(@RequestParam("driverPhone") String driverPhone) {
        return driverService.getDriverUserByPhone(driverPhone);
    }

    /**
     * 根据车辆Id查询订单需要的司机信息
     * @param carId
     * @return
     */
    @GetMapping("getAvailableDriver")
    public ResponseResult<OrderDriverResponse> getAvailableDriver(@RequestParam("carId") Long carId){
        return driverService.getAvailableDriver(carId);
    }


    /**
     * 根据司机手机号查询司机和车辆绑定关系
     * @param driverPhone
     * @return
     */
    @GetMapping("/getDriverCarRelationShip")
    public ResponseResult<DriverCarBindingRelationship> getDriverCarRelationShip(@RequestParam("driverPhone") String driverPhone){
        return driverCarRelationshipService.getDriverCarRelationShipByDriverPhone(driverPhone);
    }

    /**
     * 多条件——查询司机列表
     * @param apiBossDriver
     * @return
     */
    @PostMapping("/findDriver")
    public ResponseResult<Page<DriverUser>> findDriver(@RequestBody ApiBossDriver apiBossDriver) {
        return driverService.findDriver(apiBossDriver);
    }

    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult<Page<DriverUser>> getAll(@RequestParam("current") Integer  current, @RequestParam("size") Integer size ) {
        return driverService.getAll(current,size);
    }
}
